import 'package:cached_network_image/cached_network_image.dart';
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:school_safe_teacher/constans/all_info.dart';
import 'package:school_safe_teacher/constans/route_constants.dart';
import 'package:school_safe_teacher/resourse/app_colors.dart';
import 'package:school_safe_teacher/widget/my_widget.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(MeState state, Dispatch dispatch, ViewService viewService) {
  return stateBar(
      child: Container(
        color: AppColors.MainBackColor,
        child: Stack(
          children: [
            Image.asset("images/me_top_bg@2x.png"),
            ListView.separated(
                padding: EdgeInsets.only(top: 74, left: 12, right: 12),
                itemBuilder: (BuildContext context, int index) {
                  switch (index) {
                    case 0:
                      return _userDetail(state, dispatch, viewService);
                    case 1:
                      return _tipTop(state, dispatch, viewService);
                    case 2:
                      return _tipBottom(state, dispatch, viewService);
                  }
                  return Container();
                },
                separatorBuilder: (BuildContext context, int index) => Divider(
                      height: 10.0,
                      color: Colors.transparent,
                    ),
                itemCount: 3)
          ],
        ),
      ),
      context: viewService.context);
}

Widget _userDetail(MeState state, Dispatch dispatch, ViewService viewService) {
  return GestureDetector(
      behavior: HitTestBehavior.opaque,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(8),
        child: Container(
          padding: EdgeInsets.only(left: 17, top: 20, bottom: 20),
          color: Colors.white,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              CachedNetworkImage(
                width: 56,
                height: 56,
                imageUrl: state.userEntity.headimg != null
                    ? state.userEntity.headimg
                    : "",
                imageBuilder: (context, imageProvider) => Container(
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    image: DecorationImage(
                        image: imageProvider,
                        fit: BoxFit.cover,
                        colorFilter: ColorFilter.mode(
                            Colors.transparent, BlendMode.colorBurn)),
                  ),
                ),
                errorWidget: (context, url, error) =>
                    Image.asset("images/avator_default@2x.png"),
                fit: BoxFit.fitWidth,
              ),
              GestureDetector(
                child: Container(
                child: Text(
                  state.userEntity.teacherName != null
                      ? state.userEntity.teacherName
                      : "登陆｜注册",
                  style: TextStyle(
                      fontWeight: FontWeight.w500,
                      fontSize: 16,
                      color: AppColors.deepTextColor),
                ),
                margin: EdgeInsets.only(left: 12),
              ),
              onTap: (){
                Navigator.of(viewService.context)
                    .pushNamed(RouteConstants.LOGIN);
              },),

            ],
          ),
        ),
      ),
      onTap: () {
        if (AllInfo.instance.token.isNotEmpty) {
          Navigator.of(viewService.context).pushNamed(RouteConstants.USER_INFO);
        } else {
          Navigator.of(viewService.context).pushNamed(RouteConstants.LOGIN);
        }
      });
}

Widget _tipTop(MeState state, Dispatch dispatch, ViewService viewService) {
  return ClipRRect(
    borderRadius: BorderRadius.circular(8),
    child: Container(
      color: Colors.white,
      child: Column(
        children: [
          Divider(),
          GestureDetector(
            child: Container(
              padding: EdgeInsets.all(16),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Image.asset(
                    "images/me_study_resource@2x.png",
                    width: 21,
                    height: 21,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10),
                    child: Text(
                      "学习资料",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                  ),
                  Expanded(child: Text("")),
                  Image.asset(
                    "images/me_arrow_right@2x.png",
                    width: 5,
                    height: 10,
                  ),
                ],
              ),
            ),
            onTap: () {
              showToast("敬请期待");
            },
          ),
          Divider(),
          GestureDetector(
            child: Container(
              padding: EdgeInsets.all(16),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Image.asset(
                    "images/me_leave@2x.png",
                    width: 21,
                    height: 21,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10),
                    child: Text(
                      "请假记录",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                  ),
                  Expanded(child: Text("")),
                  Image.asset(
                    "images/me_arrow_right@2x.png",
                    width: 5,
                    height: 10,
                  ),
                ],
              ),
            ),
            onTap: () {
              showToast("敬请期待");
            },
          ),
          Divider(),
          GestureDetector(
            child: Container(
              padding: EdgeInsets.all(16),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Image.asset(
                    "images/me_member@2x.png",
                    width: 21,
                    height: 21,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10),
                    child: Text(
                      "学生出勤记录",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                  ),
                  Expanded(child: Text("")),
                  Image.asset(
                    "images/me_arrow_right@2x.png",
                    width: 5,
                    height: 10,
                  ),
                ],
              ),
            ),
            onTap: () {
              Navigator.of(viewService.context)
                  .pushNamed(RouteConstants.ATTENDANCERECORD);
            },
          ),
          Divider(),
          GestureDetector(
            child: Container(
              padding: EdgeInsets.all(16),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Image.asset(
                    "images/me_member@2x.png",
                    width: 21,
                    height: 21,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10),
                    child: Text(
                      "旷课提交",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                  ),
                  Expanded(child: Text("")),
                  Image.asset(
                    "images/me_arrow_right@2x.png",
                    width: 5,
                    height: 10,
                  ),
                ],
              ),
            ),
            onTap: () {
              Navigator.of(viewService.context)
                  .pushNamed(RouteConstants.TRUANCYSUBMISSION);
            },
          ),
        ],
      ),
    ),
  );
}

Widget _tipBottom(MeState state, Dispatch dispatch, ViewService viewService) {
  return ClipRRect(
    borderRadius: BorderRadius.circular(8),
    child: Container(
      color: Colors.white,
      child: Column(
        children: [
          GestureDetector(
            child: Container(
              padding: EdgeInsets.all(16),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Image.asset(
                    "images/me_suggest@2x.png",
                    width: 21,
                    height: 21,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10),
                    child: Text(
                      "帮助与反馈",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                  ),
                  Expanded(child: Text("")),
                  Image.asset(
                    "images/me_arrow_right@2x.png",
                    width: 5,
                    height: 10,
                  ),
                ],
              ),
            ),
            onTap: () {
              Navigator.of(viewService.context).pushNamed(RouteConstants.SUGGEST);
            },
          ),
          Divider(),
          // GestureDetector(
          //   child: Container(
          //     padding: EdgeInsets.all(16),
          //     child: Row(
          //       crossAxisAlignment: CrossAxisAlignment.center,
          //       children: [
          //         Image.asset(
          //           "images/me_evalution@2x.png",
          //           width: 21,
          //           height: 21,
          //         ),
          //         Container(
          //           margin: EdgeInsets.only(left: 10),
          //           child: Text(
          //             "给我们好评",
          //             style: TextStyle(
          //                 fontSize: 15,
          //                 fontWeight: FontWeight.normal,
          //                 color: AppColors.deepTextColor),
          //           ),
          //         ),
          //         Expanded(child: Text("")),
          //         Image.asset(
          //           "images/me_arrow_right@2x.png",
          //           width: 5,
          //           height: 10,
          //         ),
          //       ],
          //     ),
          //   ),
          //   onTap: () {},
          // ),
          // Divider(),
          GestureDetector(
            child: Container(
              padding: EdgeInsets.all(16),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Image.asset(
                    "images/me_setting@2x.png",
                    width: 21,
                    height: 21,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10),
                    child: Text(
                      "设置",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                  ),
                  Expanded(child: Text("")),
                  Image.asset(
                    "images/me_arrow_right@2x.png",
                    width: 5,
                    height: 10,
                  ),
                ],
              ),
            ),
            onTap: () {
              Navigator.of(viewService.context)
                  .pushNamed(RouteConstants.SETTING);
            },
          ),
        ],
      ),
    ),
  );
}
